#include <iostream>
#include <fstream>
#include <yaml-cpp/yaml.h>
#include <iostream>
#include <assert.h>

int main()
{
    YAML::Node node1;
    assert(node1.IsNull());  //1. 初始化的节点是Null类型

    node1["key"] = "value"; //2. 当你给它赋值键值对，它转变为Map类型
    node1["number"] = 255;
    assert(node1.IsMap());
    node1["seq"].push_back("first element");//seq对应的是一个Sequence
    node1["seq"].push_back("second element");
    std::cout << node1 << std::endl;
    /*输出结果：
    key: value
    number: 255
    seq:
    - first element
    - second element
    */
    node1.remove("key"); //删除

    YAML::Node node2;
    node2.push_back("first item");//3. 它是一个sequence类型
    node2.push_back("second_item");
    node2.push_back("third_item");
    std::vector<int> v = {1,3,5,7,9};//给node_2插入了一个Sequence
    node2.push_back(v);
    assert(node2.IsSequence());//当然，node_2仍然是一个Sequence
    for(auto it = node2.begin(); it != node2.end(); it++)
        std::cout << *(it) << std::endl;
    /*输出结果：
    first item
    second_item
    third_item
    - 1
    - 3
    - 5
    - 7
    - 9
    */
    node2.remove(0);//删除first item
    node2[0] = "new fir";
    /*修改后
    second_item
    new fir
    - 1
    - 3
    - 5
    - 7
    - 9
    */
}
